package com.lipaluma.xml.mapping;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import com.lipaluma.field.mapper.AutomaticFieldMapper;
import com.lipaluma.field.mapper.multiple.MultipleFieldMapper;

@XmlRootElement(name=XmlMultipleColumnsMapping.MULTIPLE_COLUMNS)
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlMultipleColumnsMapping extends AbstractXmlFieldMapping {
	public static final String MULTIPLE_COLUMNS = "multiple-columns";
	
	@XmlElementWrapper
	@XmlElement(name="index")
	private Integer[] indexes;
	@XmlElementWrapper
	@XmlElement(name="name")
	private String[] columnNames;
	@XmlElementWrapper(name="indexes-out")
	@XmlElement(name="index")
	private Integer[] indexesOut;
	@XmlElementWrapper
	@XmlElement(name="length")
	private Integer[] lengths;
	
	@XmlAttribute
	private Class<? extends MultipleFieldMapper> with;

	public Integer[] getIndexes() {
		if(indexes == null)
			return new Integer[0];
		return indexes;
	}
	public String[] getColumnNames() {
		if(columnNames == null)
			return new String[0];
		return columnNames;
	}
	public Integer[] getIndexesOut() {
		if(indexesOut == null)
			return new Integer[0];
		return indexesOut;
	}
	public Integer[] getLengths() {
		if(lengths == null)
			return new Integer[0];
		return lengths;
	}

	@Override
	public Class<? extends MultipleFieldMapper> with() {
		if(with == null)
			return AutomaticFieldMapper.class;
		return with;
	}
	@Override
	public boolean isMultiple() {
		return true;
	}
}
